;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.JckOverseaWarehouseInOutMoneyReport", [])
        .controller("JckOverseaWarehouseInOutMoneyReportCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService) {
            $scope.markInfo = {
                curRow: -1
            };
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/report/jckOverseaWarehouseInOutMoneyReportExport")
            };
            $scope.condition = {};
            $scope.conditionTemp = {};
            $scope.dataList = [];
            $scope.toolbarConfig = {};
            $scope.tbConf = {
                scrollWidth: 1500,
                tableCol: [
                    {
                        name: "公司名称",
                        dataField: "companyName",
                        width: 160,
                        isShow: true
                    },
                    {
                        name: "零件编号",
                        dataField: "materialNo",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "零件中文名",
                        dataField: "materialName",
                        width: 150,
                        isShow: true
                    },
                    {
                        name: "英文描述",
                        dataField: "materialsDesEn",
                        width: 150,
                        isShow: true
                    },
                    {
                        name: "数量",
                        dataField: "amount",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "单价",
                        dataField: "price",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "金额",
                        dataField: "totalPrice",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "仓库编码",
                        dataField: "warehouseCode",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "出入库单据号",
                        dataField: "businessOrder",
                        width: 200,
                        isShow: true
                    },
                    {
                        name: "出入库描述",
                        dataField: "businessType",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "出入库时间",
                        dataField: "createTimeShow",
                        width: 150,
                        isShow: true
                    },
                    {
                        name: "单据类型",
                        dataField: "recordType",
                        width: 100,
                        isShow: true
                    },
                ]
            };

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index
            };

            $scope.reset = function () {
                $scope.condition = {};
                $scope.conditionTemp = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                var service = "device";
                var reqUrl = "/report/jckOverseaWarehouseInOutMoneyReport";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = angular.copy($scope.condition);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.createTimeShow = $filter("YbDate")(item.createTime, "yyyy-MM-dd HH:mm:ss");
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            $scope.handleTextareaData = function (tempKey, key) {
                $scope.condition[key] = trimList(UserContextService.MultiInput($scope.conditionTemp[tempKey]).split(','))
            };

            function trimList(list) {
                let after = [];
                angular.forEach(list, item => {
                    item = item.trim();
                    item && (after.push(item))
                })
                return after
            }

            $scope.onCompanySelected = function() {
                $scope.condition.companyNameList = $scope.conditionTemp.companyNames
            };

            function getJckAndOverseaCompanys() {
                if (!$scope.isJCHK) return

                var service = "device";
                var reqUrl = "/company/listJckAndOversea";
                ybHttp.Get(service, reqUrl).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.jckAndOverseaCompanyList = resp.value || [];
                });
            }

            (function () {
                getJckAndOverseaCompanys()
            })();
        }])
    ;
})(window, window.angular);